const app = getApp()

Page({
    data: {
      inputWidth:0
    },

    onReady: function(){
      var windowWidth=wx.getSystemInfoSync().windowWidth;
      this.setData({ inputWidth: windowWidth-102});
      console.log(windowWidth-102);
    },

    doLogin: function(e){
      var formObject=e.detail.value;
      var username = formObject.username;
      var password = formObject.password;
      if (username.length == 0 || password.length==0){
        wx.showToast({
          title: '用户名密码不能为空',
          icon:'none',
          duration:3000
        })
      }else{
        var serverURL=app.serverURL;
        wx.showLoading({
          title: '请等待...',
        });
        wx.request({
          url: serverURL+'/login',
          method:'post',
          data:{
            username: username,
            password: password
          },
          header: {
            'content-type': 'application/json' // 默认值
          },
          success(res) {
            wx.hideLoading();
            if(res.data.status==200){
              wx.showToast({
                title: '登录成功',
                icon: 'success',
                duration: 3000
              });
              app.userInfo=res.data.data;
              wx.navigateTo({
                url: '../mine/mine',
              })
            } else if(res.data.status==500){
              wx.showToast({
                title: res.data.msg,
                icon: 'none',
                duration: 3000
              });
            }
          }
        })
      }
    },
    goRegistPage(){
      wx.navigateTo({
        url: '../userRegist/regist',
      })
    }
})